package com.serviceImpl;

import java.util.Date;
import java.util.List;

import com.dao.*;
import com.entity.*;
import com.service.DeviceService;

public class DeviceServiceImpl implements DeviceService {

	private DeviceDao deviceDao;
	
	
	public void setDeviceDao(DeviceDao deviceDao) {
		this.deviceDao = deviceDao;
	}


	@Override
	public boolean editDeviceStatus(int deviceID, int optype) {
		Device device = deviceDao.FindDeviceByID(deviceID);
		device.setDeviceStatus(optype);
		Date date = new Date();
		switch(optype){
			case 2:device.setFirstRunDate(date);break;
			case 6:device.setSecondRunDate(date);break;
			case 8:device.setInvalidatedDate(date);break;
		}
		return deviceDao.updateDevice(device);
	}


	@Override
	public List<Device> findDeviceByNorm(String deviceType, String deviceNorm) {
		return deviceDao.findDeviceByNorm(deviceType, deviceNorm);
	}

	@Override
	public List<Device> findDeviceByTypeAndNorm(String deviceType,String deviceNorm){
		return deviceDao.findDeviceByTypeAndNorm(deviceType, deviceNorm);
	}
	
	@Override
	public List<Device> findDeviceByUnit(String unitNo, String substationNo) {
		return deviceDao.findDeviceByUnit(unitNo, substationNo);
	}
	
	@Override
	public List<Device> findAllDevice(){
		return deviceDao.findAllDevice();
	}
	
	@Override
	public List<Device> findAuditingDevice(){
		return deviceDao.findAuditingDevice();
	}


	@Override
	public boolean addDevice(Device device) {
		device.setDeviceStatus(0);
		return deviceDao.addDevice(device);
	}


	@Override
	public boolean checkDeviceNoAvailable(String deviceNo) {
		return deviceDao.checkDeviceNoAvailable(deviceNo);
	}


	@Override
	public List<Device> findDeviceNotInUnitInterval() {
		return deviceDao.findDeviceNotInUnitInterval();
	}


	@Override
	public List<Device> findDeviceBySubstation(String substationNo) {
		return deviceDao.findDeviceBySubstation(substationNo);
	}


	@Override
	public List<Device> findDeviceBySubstationNotInUnitInterval(
			String substationNo) {
		return deviceDao.findDeviceBySubstationNotInUnitInterval(substationNo);
	}

	@Override
	public Device findDeviceByNo(String deviceNo) {
		return deviceDao.FindDeviceByNo(deviceNo);
	}
	
	@Override
	public List<Device> deviceDetails(String unitNo,String substationNo){
		return deviceDao.deviceDetails(unitNo,substationNo);
	}
	
	@Override
	public void deleteDevice(int deviceId){
		deviceDao.deleteDevice(deviceId);
	}

}
